<?php
class do_db {
    public  $tab;
    public  $dates;
    public  $db;
    private $tabinfo;

    function   __construct($tab,$dates,$db) {
        $this->tab=$tab;
        $this->dates=$dates;
        $this->db=$db;

    }
    function  myInstert($datas) {
        foreach ($datas as  $k=>$v) {
            if($i<count($datas)-1) {
                $string.="`$k`,";

                $valu.="'$v',";
            }else {

                $string.="`$k`";

                $valu.="'$v'";
            }

        }
        $sql="INSERT into `$this->tab` ($string) value($valu)";
        $sql=str_replace(',)', ')', $sql);
        return  $this->db-> QueryRS($sql);

    }

    function  do_sql($sql){

        return  $this->db->QueryRS($sql);

    }

    function edit($datas,$where ) {
        $i=1;
        foreach ($datas as  $k=>$v) {

            if($i<count($datas)) {
                $str.="`$k`='$v',";
            }else {

                $str.="`$k`='$v'";
            }
            $i++;
        }
        $sql="update  `$this->tab` set  $str $where ";
        $this->db-> QueryRS($sql);
    }
    function  del($where) {
      
    $sql=" delete from `$this->tab` $where ;
            ";$this->db-> QueryRS($sql);
    }
    
    function  myselect ($v='*' ,$type=1,$where='') {
        $sql="select $v  from $this->tab ";
        if($where!='')$sql.=" $where";

/// echo $sql;
        if($type==1) {
            return $this->db->FetchArray($sql);
        }else {
            return $this->db->FetchOne($sql);
        }

    }

    function  myselect_cache ($v='*' ,$type=1,$where='',$live_time=3600) {
        $sql="select $v  from $this->tab ";
        if($where!='')$sql.=" $where";
     
        if($type==1) {
            return $this->db->FetchArray_cache($sql,$live_time);
        }else {
            return $this->db->FetchOne_cache($sql,$live_time);
        }

    }


}
?>